<template>
    <div class="component-category-card">
      <h2 class="component-card-title">分类</h2>
      <div class="component-category-cloud">
        <span v-for="(item, index) in categories" 
              :key="index" 
              @click="goCategoryArticleListPage(item.categoryId, item.name)"
              class="component-category-item">
          {{ item.name }}
        </span>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  import { getCategories } from '@/api/frontend/category'
  
  const router = useRouter()
  const categories = ref([])
  
  // 获取分类
  getCategories().then((e) => {
    console.log('获取分类数据')
    console.log(e)
    categories.value = e.data
  })
  
  const goCategoryArticleListPage = (id, name) => {
    console.log('跳转 id' + id)
    router.push({path: `/category/list/${id}/${name}`})
  }
  </script>
  
  <style scoped>
  .component-category-card {
    margin-bottom: 0.75rem;
    padding: 1.25rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0;
  }
  
  .component-card-title {
    margin-bottom: 0.5rem;
    font-weight: 700;
    color: #111827;
    text-transform: uppercase;
  }
  
  .component-category-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  
  .component-category-item {
    display: inline-block;
    background-color: #ecfdf5;
    color: #047857;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.125rem 0.625rem;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
  }
  
  .component-category-item:hover {
    background-color: #047857;
    color: white;
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  
  /* 深色模式适配 */
  @media (prefers-color-scheme: dark) {
    .component-category-card {
      background-color: #1f2937;
      border-color: #374151;
    }
  
    .component-card-title {
      color: #f9fafb;
    }
  
    .component-category-item:hover {
      background-color: #059669;
      color: white;
    }
  }
  </style>  
